﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Heyo.Controls
{
    /// <summary>
    /// Avatar.xaml 的交互逻辑
    /// </summary>
    public partial class Avatar : ClippingBorder
    {
        public Avatar()
        {
            InitializeComponent();
            //Loaded += (s,e)=>{ defaultImageSource = AvatarImage.Clone(); } ;
        }
        private readonly ImageSource _defaultImageSource=new BitmapImage();
        [Category("Appearance")]
        public double AvatarBorderThickness
        {
            get => BorderThickness.Left;
            set => BorderThickness=new Thickness (value);
        }
        


        public static readonly DependencyProperty AvatarImageProperty = DependencyProperty.Register(
            "AvatarImage", typeof(ImageSource), typeof(Avatar), new PropertyMetadata(default(ImageSource),
                (s, e) =>
                {
                    var avatar= (Avatar)s;
                    avatar.Background = e.NewValue == null ? 
                        new ImageBrush(avatar._defaultImageSource) : new ImageBrush((ImageSource)e.NewValue);
                }
                ));

        [Category("Appearance")]
        public ImageSource AvatarImage
        {
            get => (ImageSource) GetValue(AvatarImageProperty);
            set => SetValue(AvatarImageProperty, value);
        }
    }
}
